﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Text;

namespace Dapper_Core.Common
{
    public class AutoMapperUtility
    {
        /// <summary>
        /// 把T1对象转换为T2
        /// </summary>
        /// <typeparam name="T1">源类型</typeparam>
        /// <typeparam name="T2">目标类型</typeparam>
        /// <param name="from"></param>
        /// <returns></returns>
        public static T2 Map<T1, T2>(T1 from)
        {
            var config = new MapperConfiguration(cfg => cfg.CreateMap<T1, T2>());
            IMapper mapper = config.CreateMapper();
            T2 to = mapper.Map<T2>(from);
            return to;
        }
    }
}
